# compiler
CC ?= ${CROSS-BULID}gcc
AR ?= ${CROSS-BULID}ar
CFLAGS := -Wall -O2 -I../include
LDFLAGS ?= -L../lib -lwflyctrl

# libs in other dir
LIB_WFLYCTRL = ../lib/libwflyctrl.a
LIBS = ${LIB_WFLYCTRL}

PUBLIC_HEADER = ../include/wflyctrl.h

DEPEND_DIRS = ./pca9685

OBJS = wflyctrl.o demo.o

# default target
default: ${DEPEND_DIRS} ${LIB_WFLYCTRL} demo

demo: demo.o
	${CC} ${CFLAGS} -o $@ $< ${LDFLAGS}
# libs and objs
.PHONY: ${DEPEND_DIRS} demo
%.o:
${DEPEND_DIRS}:
	${MAKE} -C $@
${LIB_WFLYCTRL}: wflyctrl.o ${DEPEND_DIRS}/pca9685.o ${DEPEND_DIRS}/i2c.o
	${AR} rcs $@ $^
${PUBLIC_HEADER}: wflyctrl.h
	cp $< $@

# cleanup
clean:
	${RM} demo
distclean: clean
	${RM} ${OBJS} ${LIB_WFLYCTRL} ${PUBLIC_HEADER}
	$(foreach dir, ${DEPEND_DIRS}, sh -c "${MAKE} -C $(dir) distclean";)
